<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>鼠标拾取地图坐标</title>
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
    <link rel="stylesheet" href="/static/css/map.css?v=$resourceVersion">
    <script type="text/javascript"
            src="https://webapi.amap.com/maps?v=1.3.0&key=f1f33bd3367b2d260a1c6bf07de11ebc&plugin=AMap.Autocomplete,AMap.Geocoder,AMap.Scale"></script>
    <script type="text/javascript" src="/jars/jquery/jquery-3.3.1.js"></script>
</head>
<body>
<div id="container" class="addr-map"></div>
<div id="myPageTop">
    <div class="btns-box">
        <input type="button" value="确定" class="J_sure btn-blue">
        <input type="hidden" id="longitude" value="$!longitude">
        <input type="hidden" id="latitude" value="$!latitude">
    </div>
</div>
<script type="text/javascript">
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        } else {
            return null;
        }
    }

    $(function () {
        var id = GetQueryString("id");
        var longitude = GetQueryString("longitude");
        var latitude = GetQueryString("latitude");

        $(".J_sure").on("click", function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.$("#longitude").eq(id).val($("#longitude").val());
            parent.$("#latitude").eq(id).val($("#latitude").val());
            parent.$("#longitude").eq(id).trigger('propertychange');
            parent.$("#latitude").eq(id).trigger('propertychange');
            parent.layer.close(index);
        });

        var lon = 71094169 / 600000;
        var lat = 18857989 / 600000;

        var center = longitude && latitude ? [longitude, latitude] : [lon, lat];
        //地图
        var map = new AMap.Map("container", {
            resizeEnable: true,
            center: center,
            zoom: 13
        });
        var marker = new AMap.Marker({
            position: map.getCenter(),
            draggable: true,
            cursor: 'move',
            raiseOnDrag: true,
            map: map
        });
        //尺度规格
        var scale = new AMap.Scale({
            visible: true
        });
        map.addControl(scale);
        //marker.setMap(bmap);
        //为地图注册click事件获取鼠标点击出的经纬度坐标
        var clickEventListener = map.on('click', function (e) {
            map.clearMap();
            marker = new AMap.Marker({
                position: map.getCenter(),
                draggable: true,
                cursor: 'move',
                raiseOnDrag: true,
                map: map
            });

            var lnglat = [e.lnglat.getLng(), e.lnglat.getLat()];
            marker.setPosition(lnglat);

            document.getElementById("longitude").value = e.lnglat.getLng();
            document.getElementById("latitude").value = e.lnglat.getLat();
        });
        debugger
        /*var m = new AMap.Marker({
            position: baidu,
            draggable: true,
            cursor: 'move',
            raiseOnDrag: true,
            bmap:bmap
        });*/
        //百度地图经纬度转高德
        //var baidu = [120.228084, 30.323391];
        var baidu = [lon, lat];
        AMap.convertFrom(baidu, 'gps', function (status, result) {
            debugger
            if (result.info === 'ok') {
                var lnglats = result.locations; // Array.<LngLat>
                var m = new AMap.Marker({
                    position: lnglats[0],
                    draggable: true,
                    cursor: 'move',
                    raiseOnDrag: true,
                    map:map
                });
            }
        });

        /*var g = [120.131292, 30.264455];
        var m = new AMap.Marker({
            position: g,
            draggable: true,
            cursor: 'move',
            raiseOnDrag: true,
            bmap: bmap
        });*/

    });

</script>
</body>
</html>